package com.hqyj.freemovie.front.controller;

import com.hqyj.freemovie.front.domain.MovieType;
import com.hqyj.freemovie.front.json.R;
import com.hqyj.freemovie.front.service.MovieTypeService;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("type")
public class MovieTypeController extends BaseController {

    @Resource
    private MovieTypeService movieTypeService;


    @GetMapping("/")
    //将来存到redis中，键的名字是什么呢？cacheName+key
    //movieTypes.queryAllMovieTypes ==>key ==>R对象
    @Cacheable(cacheNames="movieTypes",key = "#root.method.name")
    public R queryAllMovieTypes() {
        List<MovieType> movieTypeList = new ArrayList<MovieType>();
        try {
            movieTypeList = movieTypeService.queryAllMovieTypes();
            return R.success("查询电影类型列表成功！", movieTypeList);
        } catch (Exception ex) {
            ex.printStackTrace();
            return R.error("程序出现异常！");
        }
    }
}
